package com.ildepinc.persistence.concretes.models;

import java.sql.Timestamp;
import java.util.HashMap;

import com.ildepinc.persistence.abstracts.TableAuditableExpirable;
import com.ildepinc.persistence.enums.NewProgressiveMethod;
// You should customize this class
// depending on the database engine
// you want to use.
// This version is for Apache Derby
public class Country extends TableAuditableExpirable {

  // CREATE TABLE DEVSCHEMA.COUNTRIES (
  //   ID INT NOT NULL,
  //   ISO_693_1 VARCHAR(2) NOT NULL,
  //   NAME VARCHAR(250) NOT NULL,
  //   INSERTED_AT TIMESTAMP NOT NULL,
  //   INSERTED_BY VARCHAR(255) NOT NULL,
  //   UPDATED_AT TIMESTAMP NOT NULL,
  //   UPDATED_BY VARCHAR(255) NOT NULL,
  //   ACTIVE BOOLEAN NOT NULL,
  //   VALID_FROM TIMESTAMP NOT NULL,
  //   VALID_TO TIMESTAMP NOT NULL,
  //   CONSTRAINT COUNTRIES_PK PRIMARY KEY (ID)
  // );

  private Long id;
  private String iso6391;
  private String name;

  public Country() {
    this.clear();
  }

  public Country(
    Long id, String iso6391, String name,
    Timestamp insertedAt, String insertedBy,
    Timestamp updatedAt, String updatedBy,
    Boolean active, Timestamp validFrom, Timestamp validTo,
    String schema
    ) {
    this.clear();
    this.setDefaults(schema);
    this.id = id;
    this.iso6391 = iso6391;
    this.name = name;
    this.setInsertedAt(insertedAt);
    this.setInsertedBy(insertedBy);
    this.setUpdatedAt(updatedAt);
    this.setUpdatedBy(updatedBy);
    this.setActive(active);
    this.setValidFrom(validFrom);
    this.setValidTo(validTo);
  }

  public Country(String schema) {
    this.clear();
    this.setDefaults(schema);
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getIso6391() {
    return iso6391;
  }

  public void setIso6391(String iso6391) {
    this.iso6391 = iso6391;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void setDefaults(String schema) {
    this.setSchema(schema);
    this.setTableName("COUNTRIES");
    String fullQualifiedName = this.getSchema() + "." + this.getTableName();
    this.setPrimaryKeys(new HashMap<String, Object>() {
      {
        put("ID", null);
      }
    });
    this.setPkSingleColumn(true);
    this.setPkAutoIncremental(false);
    this.setSqlCreateTable("CREATE TABLE " + fullQualifiedName + " (" + " ID INT NOT NULL,"
        + " ISO_639_1 VARCHAR(2) NOT NULL," + " NAME VARCHAR(250) NOT NULL,"
        + " INSERTED_AT TIMESTAMP NOT NULL," + " INSERTED_BY VARCHAR(255) NOT NULL,"
        + " UPDATED_AT TIMESTAMP NOT NULL," + " UPDATED_BY VARCHAR(255) NOT NULL,"
        + " ACTIVE BOOLEAN NOT NULL,"
        + " VALID_FROM TIMESTAMP NOT NULL," + " VALID_TO TIMESTAMP NOT NULL,"
        + " CONSTRAINT COUNTRIES_PK PRIMARY KEY (ID)"
        + " )");
    this.setSqlInsert("INSERT INTO " + fullQualifiedName
        + " ( ID, ISO_639_1, NAME,"
        + " INSERTED_AT, INSERTED_BY, UPDATED_AT, UPDATED_BY,"
        + " ACTIVE, VALID_FROM, VALID_TO) "
        + " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
    this.setSqlUpdate("UPDATE " + fullQualifiedName
        + " SET ISO_639_1=?, NAME=?,"
        + " UPDATED_AT=?, UPDATED_BY=?,"
        + " ACTIVE=?, VALID_FROM=?, VALID_TO=?");
    this.setSqlSelect("SELECT * FROM " + fullQualifiedName);
    this.setSqlDelete("DELETE FROM " + fullQualifiedName);
    this.setNewProgressiveMethod(NewProgressiveMethod.NEXT_AVAILABLE);
  }

  @Override
  public void clear() {
    super.clear();
    this.id = null;
    this.name = null;
    this.iso6391 = null;
  }

}
